<?php

namespace app\model;

use think\Model;

class DeliveryData extends Model
{
    // 设置当前模型对应的数据表
    protected $name = 'delivery_data';
    // 设置当前模型主键
    protected $pk = 'id';

    // 获取累计成本
    public function getTotalCost($where)
    {
        return $this->where($where)->sum('total_cost');
    }

    // 根据条件获取数据
    public function getDataByWhere($where = [], $fields = 'id')
    {
        $data = $this::where($where)->field($fields)->select();
        return $data ? $data->toArray() : [];
    }
}